package com.gitee.huanminabc.utils_common.test;

public class DurationRunCodeUtil {

    //脱离主线程持续执行代码
    public static void runCode(Runnable runnable, long duration) {
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(duration);
                    runnable.run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    public static void runCode(Runnable runnable) {
        runCode(runnable, 1000);
    }
}
